package pers.twf.twfRpc.protocol;

import lombok.Getter;
import pers.twf.twfRpc.serializer.SerializerKeys;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

@Getter
public enum ProtocolMessageSerializerEnum implements SerializerKeys {

    JDK(0,SerializerKeys.JDK),
    JSON(1,SerializerKeys.JSON),
    KRYO(2,SerializerKeys.KRYO),
    HESSIAN(3,SerializerKeys.HESSIAN);

    private final int key;
    private final String name;

    ProtocolMessageSerializerEnum(int key, String name) {
        this.key = key;
        this.name = name;
    }

    public static List<String> getNameS() {
        return Arrays.stream(values()).map(item->item.name).collect(Collectors.toList());
    }

    /**
     * @param key
     * @return
     */
    public static ProtocolMessageSerializerEnum getEnumBySerializer(int key) {
        for (ProtocolMessageSerializerEnum protocolMessageSerializerEnum : ProtocolMessageSerializerEnum.values()) {
            if (protocolMessageSerializerEnum.getKey() == key) {
                return protocolMessageSerializerEnum;
            }
        }
        return null;
    }

    /**
     * @param name
     * @return
     */
    public static ProtocolMessageSerializerEnum getEnumByName(String name) {
        for (ProtocolMessageSerializerEnum protocolMessageSerializerEnum : ProtocolMessageSerializerEnum.values()) {
            if (protocolMessageSerializerEnum.getName().equals(name)) {
                return protocolMessageSerializerEnum;
            }
        }
        return null;
    }







}
